import { instance as http } from "../axios";
// import axios from "axios";

// export function getIp() {
//     return axios.get('/getIp').then(success => {
//         return success
//     }).catch(error => {
//         throw error
//     })
// }


/** 以下是发送给vsitorController的 **/
//发送当前用户ip地址
export function saveVisitorIp(ip: string) {
    return http.get(`/visitor/addVisitor?ip=${ip}`).then(
        success => {
            return success
        }
    ).catch(error => {
        throw error
    })
}


/** 以下是ArticleController请求 **/
//获取文章相关信息
export function getArticleList(pageNum: number) {//传过来文章页数
    return http.get(`/article/getArticleList?pageNum=${pageNum}`).then(success => {
        return success
        // arr.value = success.data.data.data
        // console.log(success.data.data.data);//这是一个数组
        // console.log(success.data.data.data[0]);//第一个数据
    }).catch(error => {
        throw error
    })
}

//发过去一个json对象,更改文章相关信息
export function editArticle(article: any) {
    return http.post('/article/updateArticle', article).then(success => {
        return success
    }).catch(error => {
        throw error
    })
}
//根据id得到文章的详细内容
export function getOneArticle(id: any) {
    return http.get(`/article/getArticle?id=${id}`).then(success => {
        return success
    }).catch(error => {
        throw error
    })
}
//根据id保存文章内容
export function saveArticle(id: any, content: any) {//接收id,和要发送的内容
    let data = {
        'articleId': id,
        'content': content
    }
    return http.post('/article/saveArticle', data).then(success => {
        return success
    }).catch(error => {
        throw error
    })
}
//根据id/ids删除文章 传过来需要拼接的字符串
export function deleteByIds(path: any) {
    return http.delete(`/article/deleteByIds?${path}`).then(success => {
        return success
    }).catch(error => {
        throw error
    })
}
//创建文章的基本信息
export function createArticle(data:any){
    return http.post('/article/createArticle',data).then(success => {
        return success
    }).catch(error => {
        throw error
    })
}

/** 下面是关于用户的一些请求 */

//登录
export function login(username:any,password:any){
    let user={
        'username':username,
        'password':password
    }
    return http.post('/user/login',user).then(success => {
        return success
    }).catch(error => {
        throw error
    })
}

//发送匿名消息的api



